package thread;

//Thread创建线程

class MyThread01 extends Thread{

    //这里是 创建好线程之后要执行的操作
    @Override
    public void run() {

        while(true){
            System.out.println("Thread");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }
}


public class Demo2 {

    //调用main的线程是主线程
    public static void main(String[] args) {

        //这里只是创建了线程的对象
        MyThread t = new MyThread();

        //此处才是正在创建线程
        t.start();

        while(true){
            System.out.println("main");

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

}
